﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace nanobot {
    public partial class CancelOrder_Form : Form {
        System.Timers.Timer t;
        public CancelOrder_Form ( string[] currencyPair ) {
            InitializeComponent();
            if ( currencyPair == null ) {
                t = new System.Timers.Timer( 1000 );
                t.Elapsed += t_Elapsed;
                t.AutoReset = true;
                t.Start();
            } else {
                comboBox.DataSource = currencyPair;
                button2.Enabled = true;

            }
        }

        void t_Elapsed ( object sender, System.Timers.ElapsedEventArgs e ) {
            if ( POLONIEXcom.Pairs != null ) {
                SetDataSource_ThreadSafe( comboBox, POLONIEXcom.Pairs );
                ChangeEnablePropertyForControl_ThreadSafe( button2, true );
                
                ( sender as System.Timers.Timer ).Stop();
            }
        }

        private void textBox_KeyPress ( object sender, KeyPressEventArgs e ) {
            if ( !Char.IsDigit( e.KeyChar ) ) {
                e.Handled = true;

            }
        }


        public void SetDataSource_ThreadSafe ( ComboBox varControl, string[] list ) {
            if ( varControl.InvokeRequired ) {
                varControl.Invoke( new Action<ComboBox, string[]>( SetDataSource_ThreadSafe ), new Object[] { varControl, list } );
                return;

            } else {
                varControl.DataSource = list;

            }
        }
        private void ChangeEnablePropertyForControl_ThreadSafe ( Control varControl, bool b ) {
            if ( varControl.InvokeRequired ) {
                varControl.Invoke(
                    new Action<Control, bool>( ChangeEnablePropertyForControl_ThreadSafe ),
                    new object[] { varControl, b }
                    );
            } else {
                varControl.Enabled = b;
            }


        }


    }
}
